package com.ota.client.api;

public enum UpgradeStatus {
    // 枚举常量，指定整数值和字符名称
    PENDING(0, "Pending"),
    IN_PROGRESS(1, "In Progress"),
    COMPLETED(2, "Completed"),
    FAILED(3, "Failed");

    // 定义字段
    private final int value;
    private final String name;

    // 构造方法
    UpgradeStatus(int value, String name) {
        this.value = value;
        this.name = name;
    }

    // 获取整数值
    public int getValue() {
        return value;
    }

    // 获取字符名称
    public String getName() {
        return name;
    }

    // 根据整数值获取对应的枚举
    public static UpgradeStatus fromValue(int value) {
        for (UpgradeStatus status : values()) {
            if (status.getValue() == value) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid value: " + value);
    }

    // 根据字符名称获取对应的枚举
    public static UpgradeStatus fromName(String name) {
        for (UpgradeStatus status : values()) {
            if (status.getName().equalsIgnoreCase(name)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid name: " + name);
    }
}
